#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 505;

int n, m;
struct Node {
  int x, y;
} a[N];
int x[N], y[N], row, col;
int b[N][N];
int sum[N][N];
bool check(int d) {
  rep(i, 1, row) rep(j, 1, col) {
    int ni = lower_bound(x + 1, x + row + 1, x[i] + d) - x - 1;
    int nj = lower_bound(y + 1, y + col + 1, y[j] + d) - y - 1;
    int cnt = sum[ni][nj] - sum[i - 1][nj] - sum[ni][j - 1] + sum[i - 1][j - 1];
    if (cnt >= m) return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> m >> n;
  rep(i, 1, n) {
    cin >> x[i] >> y[i];
    a[i] = Node{x[i], y[i]};
  }
  sort(x + 1, x + n + 1);
  row = unique(x + 1, x + n + 1) - x - 1;
  sort(y + 1, y + n + 1);
  col = unique(y + 1, y + n + 1) - y - 1;
  rep(k, 1, n) {
    int i = lower_bound(x + 1, x + row + 1, a[k].x) - x;
    int j = lower_bound(y + 1, y + col + 1, a[k].y) - y;
    b[i][j]++;
  }
  rep(i, 1, row) rep(j, 1, col) {
    sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + b[i][j];
  }
  int l = 1, r = 10000;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}